home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************
- *
- * PRINTER.C
- *
- **************************************************************/
-
- #include <acs.h>
- #include <acsplus.h>
- #include <stdlib.h>
- #include <string.h>
- #include <tos.h>
- #include <messages.pif>
- #include <acs_plus.pif>
- #include <diskfile.pif>
- #include "..\drawer\drawer.pif"
- #include "..\params\params.pif"
-
- #include "printer.pif"
- #include "printer.h"
- #include "printer.ah"
-
-
- /************* OBJECT DATA PROTOTYPE BEGIN ***********************/
-
- typedef struct
- {
- /*** init only data ***/
- char path[pathname_length], filename[filename_length] ;
- int print_handle, print_width, print_height ;
- int screen_handle, screen_width, screen_height ;
- Awindow *drawer_wi ;
- }
- PRINTER ;
-
- /************* OBJECT DATA PROTOTYPE END *************************/
-
-
-
- /*******************************************************************
- */
- static int service(Awindow *wi, int task, void *not_used)
- /*
- * Service routine for messages sent to the printer window.
- *
- * OUTPUT: AS_TERM ==> message is forwarded to parent
- * AS_INFO ==> a little help function
- *
- *******************************************************************/
- {
- switch (task)
- {
- case AS_TERM: Awi_sendall(TERMINATE, wi) ; return TRUE ;
- case AS_INFO: A_dialog(&PRINTER_INFO) ; return TRUE ;
- default: return FALSE ;
- }
- }
-
-
- static void to_file(void)
- {
- ev_object[INTO_ONE].ob_state ^= DISABLED ;
- Awi_obchange(ev_window, INTO_ONE, -1) ;
- }
-
- /*******************************************************************
- */
- static void go(void)
- /*
- * for the "go" button in the printer
- * window work object. A number of pages corresponding to the user's
- * entries in the work object is sent to printer or 1 page is sent to
- * metafile driver. Selection between printer and metafile driver is
- * done depending on the "to file" checkbox.
- * The metafile driver is loaded when output to file is selected.
- * Same is valid for metafile fonts.
- * The metafile is written to the path of the GEM clipboard. If no
- * path is set the GEM clipboard is set to "current drive":\clipbrd .
- * If that directory does not exist it is created.
- * The printer driver is expected to be already loaded !
- * Same is valid for printer fonts.
- *
- * OUTPUT: - a directory \clipbrd if no clipboard path is set
- * and output to file is desired
- * - one or several pages with note systems generated
- * via VDI routines on the printer or
- * the metafile workstation
- *
- *******************************************************************/
- {
- PRINTER *p = ev_window->user ;
- int first, last, page, i, length ;
- char path_buffer[pathname_length], clipboard[pathname_length], metafilename[filename_length] ;
- char *point, pagestring[9] ;
- int points[4], drive, drive_buffer ;
- unsigned long existing_drives ;
- int handle, work_in[11], work_out[57] ;
-
- /*** enable page number GEM object ***/
- Awi_obchange(ev_window, PAGE, ev_object[PAGE].ob_state & ~DISABLED) ;
-
- /*** determine first and last page to be drawn ***/
- if (ev_object[FROM_TO].ob_state & SELECTED)
- {
- first = atoi(ev_object[FROM].ob_spec.tedinfo->te_ptext) ;
- page = get_first_page(p->drawer_wi) ;
- if (first < page) first = page ;
- last = atoi(ev_object[TO].ob_spec.tedinfo->te_ptext) ;
- page = get_last_page(p->drawer_wi) ;
- if (last > page) last = page ;
- }
- if (ev_object[CURRENT].ob_state & SELECTED)
- first = last = get_current_page(p->drawer_wi) ;
- if (ev_object[ALL].ob_state & SELECTED)
- {
- first = get_first_page(p->drawer_wi) ;
- last = get_last_page(p->drawer_wi) ;
- }
- /*** print (to printer or to file ?) ***/
- if (ev_object[TO_FILE].ob_state & SELECTED)
- {
- /*** buffer current drive and path ***/
- drive_buffer = Dgetdrv() ;
- Dgetpath(path_buffer, 0) ;
-
- /*** check which drives exist (get bit table) ***/
- existing_drives = Dsetdrv(drive_buffer) ;
-
- /*** get/set clipboard path ***/
- scrp_read(clipboard) ;
- if (clipboard[0])
- {
- /*** test if clipboard path already defined physically exists ***/
- Dsetdrv( (*clipboard - 'A') & 0x1F ) ;
- if ( Dsetpath(clipboard + 2) < 0 )
- {
- alert_str(PATH_NOT_EXIST, clipboard) ;
- clipboard[0] = 0 ;
- }
- }
- else
- {
- /*** no valid clipboard path defined ***/
- existing_drives >>= 2 ; /* drive 'C' in least bit */
-
- /*** search first existing drive ***/
- for ( drive = 'C' ; drive <= 'Z' ; drive++ )
- {
- if (existing_drives & 0x0001)
- {
- clipboard[0] = drive ;
- drive = 'Z' + 2 ;
- }
- existing_drives >>= 1 ; /* test next drive */
- }
- /*** if no drive found, use current drive ***/
- if ( !clipboard[0] ) clipboard[0] = drive_buffer + 'A' ;
- clipboard[1] = 0 ;
- strcat(clipboard, ":\\CLIPBRD\\") ;
-
- /*** test if clipboard path already exists ***/
- Dsetdrv( (*clipboard - 'A') & 0x1F ) ;
- if ( Dsetpath("\\CLIPBRD\\") < 0 )
- {
- /*** directory must be created ***/
- Dsetpath("\\") ;
- if ( Dcreate("CLIPBRD") < 0 )
- {
- alert_str(DIR_NOT_CREATED, clipboard) ;
- Dsetpath(p->path) ;
- }
- else
- {
- /*** define path for clipboard ***/
- alert_str(DIR_CREATED, clipboard) ;
- Dsetpath("\\CLIPBRD\\") ;
- scrp_write(clipboard) ;
- }
- }
- }
- if (ev_object[INTO_ONE].ob_state & SELECTED)
- {
- /*** all pages into SCRAP.GEM separated by form advances ***/
- /*** open physical workstation (metafile driver) ***/
- work_in[0] = 31 ; /* metafile driver of assign.sys */
- for ( i = 1 ; i <= 8 ; i++ ) work_in[i] = 1 ;
- work_in[9] = 0 ; work_in[10] = RC ;
- v_opnwk(work_in, &handle, work_out) ;
- if (handle)
- {
- vm_filename(handle, "SCRAP.GEM") ;
-
- /*** load metafile fonts ***/
- vst_load_fonts(handle, 0) ;
-
- /*** layout and "print" ***/
- if ( page_layouter(p->screen_handle, p->screen_width, p->screen_height,
- p->drawer_wi) == LAYOUT_GOOD ) for ( page = first ; page <= last ; page++ )
- {
- itoa(page, ev_object[PAGE].ob_spec.tedinfo->te_ptext, 10) ;
- Awi_obchange(ev_window, PAGE_CARRIER, -1) ;
- points[0] = points[1] = 0 ;
- points[2] = p->screen_width ;
- points[3] = p->screen_height ;
- draw_page(handle, p->drawer_wi, 0, 0, points, 1, page) ;
- v_form_adv(handle) ;
- }
- reset_layout(p->drawer_wi) ;
- /*** never change the sequence of the following functions: PURE C error !!! ***/
- v_meta_extents(handle, 0, 0, p->screen_width, p->screen_height) ;
- vm_pagesize(handle, 2090, 2970) ; /* DIN A4 */
- vm_coords(handle, 0, p->screen_height, p->screen_width, 0) ;
-
- vst_unload_fonts(handle, 0) ;
- v_clswk(handle) ;
- }
- else alert_str(METAFILING_NOT_POSSIBLE, "") ;
- }
- else for ( page = first ; page <= last ; page++ )
- {
- /*** 1 file per page ***/
- itoa(page, ev_object[PAGE].ob_spec.tedinfo->te_ptext, 10) ;
- Awi_obchange(ev_window, PAGE_CARRIER, -1) ;
-
- /*** open physical workstation (metafile driver) ***/
- work_in[0] = 31 ; /* metafile driver of assign.sys */
- for ( i = 1 ; i <= 8 ; i++ ) work_in[i] = 1 ;
- work_in[9] = 0 ; work_in[10] = RC ;
- v_opnwk(work_in, &handle, work_out) ;
- if (handle)
- {
- /*** set file name, set extension to "GEM", include page number ***/
- strcpy(metafilename, p->filename) ;
- point = strrchr(metafilename, '.') ;
- if (!point)
- {
- point = metafilename + strlen(metafilename) ;
- point[0] = '.' ; point[1] = 0 ;
- }
- strcpy( point + 1, "GEM" ) ;
- itoa(page, pagestring, 10) ;
- length = strlen(pagestring) ;
- memcpy( point - length, pagestring, length ) ;
- vm_filename(handle, metafilename) ;
-
- /*** load metafile fonts ***/
- vst_load_fonts(handle, 0) ;
-
- /*** layout and "print" ***/
- if ( page_layouter(p->screen_handle, p->screen_width, p->screen_height,
- p->drawer_wi) == LAYOUT_GOOD )
- {
- points[0] = points[1] = 0 ;
- points[2] = p->screen_width ;
- points[3] = p->screen_height ;
- draw_page(handle, p->drawer_wi, 0, 0, points, 1, page) ;
- v_meta_extents(handle, 0, 0, p->screen_width, p->screen_height) ;
- vm_pagesize(handle, 2090, 2970) ;
- vm_coords(handle, 0, p->screen_height, p->screen_width, 0) ;
- }
- reset_layout(p->drawer_wi) ;
- vst_unload_fonts(handle, 0) ;
- v_clswk(handle) ;
- }
- else alert_str(METAFILING_NOT_POSSIBLE, "") ;
- }
-
- /*** "GEMFILE.GEM" exists because of GDOS error ? ***/
- Fdelete("GEMFILE.GEM") ; /* a workaround ! */
-
- /*** restore original drive and path ***/
- Dsetdrv(drive_buffer) ;
- Dsetpath(path_buffer) ;
- }
- else
- {
- /*** generate printed paper ***/
- if ( page_layouter(p->print_handle,
- p->print_width, p->print_height, p->drawer_wi) != LAYOUT_GOOD )
- {
- alert_str(NO_LAYOUT, "") ;
- reset_layout(p->drawer_wi) ;
- return ;
- }
- points[0] = points[1] = 0 ;
- points[2] = p->print_width - 1 ;
- points[3] = p->print_height - 1 ;
- for ( page = first ; page <= last ; page++ )
- {
- itoa(page, ev_object[PAGE].ob_spec.tedinfo->te_ptext, 10) ;
- Awi_obchange(ev_window, PAGE, -1) ;
- draw_page(p->print_handle, p->drawer_wi, 0, 0, points, 1, page) ;
- v_updwk(p->print_handle) ;
- v_clrwk(p->print_handle) ;
- }
- reset_layout(p->drawer_wi) ;
- }
- /*** disable page number GEM object ***/
- Awi_obchange(ev_window, PAGE, ev_object[PAGE].ob_state | DISABLED) ;
- }
-
-
- /*******************************************************************
- *
- * PUBLISHED INTERFACE
- *
- *******************************************************************/
-
-
- void PRINTER_destructor(Awindow *wi)
- {
- if (wi)
- {
- memory_symptom = "PrDstr wi->user" ;
- if (wi->user) My_free(wi->user) ;
- memory_symptom = "PrDstr wi" ;
- Awi_delete(wi) ;
- }
- }
-
-
- Awindow *PRINTER_constructor(PRINTER_INIT *printer_init)
- {
- Awindow *wi ;
- PRINTER *p ;
-
- /*** enter filename into icon text and info line ***/
- PRINTER_WINDOW.iconblk = printer_init->icon ;
- PRINTER_WINDOW.iconblk->monoblk.ib_ptext = printer_init->filename ;
- PRINTER_WINDOW.info = printer_init->filename ;
-
- /*** create the PRINTER window ***/
- wi = Awi_create(&PRINTER_WINDOW) ;
- if (!wi) return NULL ;
-
- /*** allocate printer structure and initialize ***/
- wi->user = p = My_alloc(sizeof *p) ;
- if (!p) { PRINTER_destructor(wi) ; return NULL ; }
- strcpy(p->filename, printer_init->filename) ;
- strcpy(p->path, printer_init->path) ;
- strrchr(p->path, '\\')[1] = 0 ;
- p->screen_handle = printer_init->screen_handle ;
- p->screen_width = printer_init->screen_width ;
- p->screen_height = printer_init->screen_height ;
- p->print_handle = printer_init->print_handle ;
- p->print_width = printer_init->print_width ;
- p->print_height = printer_init->print_height ;
- p->drawer_wi = printer_init->drawer_window ;
-
- /*** disable buttons if necessary ***/
- if (!p->print_handle)
- {
- /*** printing not possible ***/
- if (application)
- /*** only metafiling possible ***/
- wi->work[TO_FILE].ob_state |= (SELECTED | DISABLED) ;
- else
- /*** nothing possible in accessory ***/
- wi->work[GO].ob_state |= DISABLED ;
- }
- else
- {
- /*** printing possible ***/
- if (!application)
- /*** metafiling not possible in accessory ***/
- wi->work[TO_FILE].ob_state |= DISABLED ;
- }
- /*** return success message ***/
- return wi ;
- }
-
-
-